package com.base.caselib;

import android.view.View;

import com.alibaba.android.arouter.facade.annotation.Route;
import com.alibaba.android.arouter.launcher.ARouter;
import com.arvin.imagepicker.bean.ImageItem;
import com.base.caselib.bean.CertCardBean;
import com.base.caselib.bean.PersonInfo;
import com.base.caselib.databinding.ActivityAddpeopleBinding;
import com.base.caselib.presenter.AddpeoplePresenter;
import com.base.caselib.view.AddPeopleView;
import com.base.commonlib.base.CBaseBarMvpActivity;
import com.base.commonlib.utils.RxBus2;

import java.util.ArrayList;
import java.util.List;

import io.reactivex.disposables.Disposable;
import io.reactivex.functions.Consumer;

/**
 * Created by weikailiang on 2020/2/3.
 */
@Route(path = "/crpuct/addpeople")
public class AddPeopleActivity extends CBaseBarMvpActivity<AddpeoplePresenter> implements AddPeopleView {


    private PersonInfo mPersonInfo = new PersonInfo();
    private ActivityAddpeopleBinding mBinding;
    @Override
    protected int getLayoutResource() {
        return R.layout.activity_addpeople;
    }

    @Override
    protected void init() {
        super.init();
        mBinding = (ActivityAddpeopleBinding) mRootBinding;
        mBinding.setEntity(mPersonInfo);
        mPresenter = new AddpeoplePresenter(this,this);
        mPresenter.start();
        setBackNavigationTip(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                mWaringDialog.show();
            }
        });
        setBarTitle("添加人员");
        setRigImg(R.drawable.ic_camear, new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                ARouter.getInstance()
                        .build("/crpuct/camera")
                        .withString("type","3")//车辆信息
                        .navigation();
            }
        });
        mBinding.drivingFirstTimeN.setChecked(true);
        mBinding.fareN.setChecked(true);

        mBinding.save.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if (mBinding.drivingFirstTimeN.isChecked()){
                    mPersonInfo.setAreaContact(0);
                }else {
                    mPersonInfo.setAreaContact(1);
                }
                if (mBinding.fareN.isChecked()){
                    mPersonInfo.setFebrileState(0);
                }else {
                    mPersonInfo.setFebrileState(1);
                }
                if (mBinding.sexWomen.isChecked()){
                    mPersonInfo.setSex("女");
                }else {
                    mPersonInfo.setSex("男");
                }
                RxBus2.getInstance().post(mPersonInfo);
                finish();
            }
        });
    }

    @Override
    protected void start() {
        Disposable disposable = RxBus2.getInstance().doSubscribe(CertCardBean.class, new Consumer<CertCardBean>() {
            @Override
            public void accept(CertCardBean bean) throws Exception {
                mPersonInfo.setAddress(bean.getAddress());
                mPersonInfo.setIdCard(bean.getCitizenIdNumber());
                mPersonInfo.setName(bean.getName());
                mPersonInfo.setNation(bean.getEthnicity());
                mPersonInfo.setSex(bean.getSex());
                if (bean.getSex().equals("男")){
                    mBinding.sexMan.setChecked(true);
                }else {
                    mBinding.sexWomen.setChecked(true);
                }
                mBinding.setEntity(mPersonInfo);
            }
        });
        RxBus2.getInstance().addSubscription(this, disposable);
    }
}
